package com.example.leetcode.trainingcamp.week2.practice;

public class Traverse {
     // 1 2 3 4 5
    public ListNode print(ListNode head){
        ListNode pre = head;
        ListNode old = new ListNode();
        ListNode now = old;
        while (pre != null){
           now.next = pre;
           now = pre;
           pre = pre.next;
        }
       return old.next;
    }
}



class TestTraverse{
  public static void main(String[] args) {
      ListNode head = new ListNode(1);
      head.next = new ListNode(2);
      head.next.next = new ListNode(3);
      head.next.next.next = new ListNode(4);
      head.next.next.next.next = new ListNode(5);
      Traverse t = new Traverse();
      ListNode print = t.print(head);
      while (print != null){
          System.out.println("修改后的链表="+print.val);
          print = print.next;
      }

      while (head != null){
          System.out.println("原来的链表="+head.val);
          head = head.next;
      }
  }
}